/**
 * 
 */
package jnzb.control.queue.change;

import jnzb.control.NZBProcessor;
import jnzb.control.events.InfoEventProcessor;
import jnzb.control.uiUpdate.UIUpdateDelegate;
import jnzb.model.nzb.NZB;

/**
 * Performs the neccessary changes to move an nzb up the queue, including
 * waiting for the change to be made
 * 
 * @author AA1
 * 
 */
public class QueueUpChange extends QueueChangeProcessor {

	public QueueUpChange(NZBProcessor nzbProcessor,
			UIUpdateDelegate uiDelegate, InfoEventProcessor infoProcessor,
			int selectedRow) {
		super(nzbProcessor, uiDelegate, infoProcessor, selectedRow);
	}

	/**
	 * Checks if moving this item up will affect the download. i.e is it the 2nd
	 * in the queue, to be promoted to 1st
	 * 
	 * @see jnzb.control.queue.change.QueueChangeProcessor#affectsDownload(int)
	 */
	public boolean affectsDownload(int selectedRow) {
		return selectedRow == 1;
	}

	public void makeQueueChange(NZB affectedNZB) {
		int newPos = queueManager.moveUp(affectedNZB);
		if (newPos > -1) {
			uiDelegate.setSelectedQueueEntry(newPos);
		}
		infoProcessor.debug("Q Up change made");
	}

	/**
	 * Check that the NZB has been moved up to the current download. Check only
	 * made if an nzb is moved to the top position
	 * 
	 * @return
	 */
	public boolean checkChangeMade(NZB affectedNZB) {
		return this.nzbProcessor.getCurrentNZB().equals(affectedNZB);
	}
}
